/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ExibirAlterarConsulta.java
 *
 * Created on 30/11/2011, 17:11:28
 */

package view;

import control.ConsultaControler;
import dao.MedicoDao;
import dao.PacienteDao;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import model.Consulta;
import model.Paciente;

/**
 *
 * @author tais
 */
public class ExibirAlterarProntuario extends javax.swing.JFrame {
    private boolean changed = false;
    private ArrayList<Object> listaExames = new ArrayList<Object>();
    private int exameSelecionado = -1;
    private ArrayList<model.Medicacao> listaMedicacoes;
    private int medicacaoSelecionada = -1;
    private Paciente paciente;
    private Consulta consulta;
    private DefaultListModel listmodelExa = new DefaultListModel();

    /** Creates new form ExibirAlterarConsulta */
    public ExibirAlterarProntuario(Consulta c) {
        initComponents();
        initOtherComponents(c);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        nomePaciente = new javax.swing.JLabel();
        cpfPacientelabel = new javax.swing.JLabel();
        cpfPaciente1 = new javax.swing.JLabel();
        cpfPaciente2 = new javax.swing.JLabel();
        cpfPaciente = new javax.swing.JLabel();
        telefonePaciente = new javax.swing.JLabel();
        enderecoPaciente = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        nomeMedico = new javax.swing.JLabel();
        crmMedico = new javax.swing.JLabel();
        nomeConvenio = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        nomeConvenio1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        sintomas = new javax.swing.JTextArea();
        jLabel6 = new javax.swing.JLabel();
        diagnostico = new javax.swing.JTextField();
        adicionarExame = new javax.swing.JButton();
        removerExame = new javax.swing.JButton();
        Medicacoes = new javax.swing.JLabel();
        adicionarMedicacao = new javax.swing.JButton();
        removerMedicacao = new javax.swing.JButton();
        medicacoes = new javax.swing.JComboBox();
        exames = new javax.swing.JComboBox();
        exibirExame = new javax.swing.JButton();
        exibirMedicacao = new javax.swing.JButton();
        salvar = new javax.swing.JButton();
        imprimirProntuario = new javax.swing.JButton();
        Sair = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("PRONTUÁRIO");

        jPanel1.setBackground(new java.awt.Color(245, 243, 239));

        nomePaciente.setFont(new java.awt.Font("DejaVu Sans", 1, 18));
        nomePaciente.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        nomePaciente.setText("Nome do Paciente");

        cpfPacientelabel.setFont(new java.awt.Font("DejaVu Sans", 1, 14));
        cpfPacientelabel.setText("CPF:");

        cpfPaciente1.setFont(new java.awt.Font("DejaVu Sans", 1, 14));
        cpfPaciente1.setText("Telefone:");

        cpfPaciente2.setFont(new java.awt.Font("DejaVu Sans", 1, 14));
        cpfPaciente2.setText("Endereço:");

        cpfPaciente.setText("  ");

        telefonePaciente.setText(" ");

        enderecoPaciente.setText("  ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(nomePaciente, javax.swing.GroupLayout.DEFAULT_SIZE, 607, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(cpfPaciente1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cpfPaciente2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(enderecoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 458, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(telefonePaciente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(cpfPacientelabel, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cpfPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(40, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(nomePaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cpfPacientelabel)
                    .addComponent(cpfPaciente))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cpfPaciente1)
                    .addComponent(telefonePaciente))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cpfPaciente2)
                    .addComponent(enderecoPaciente))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jPanel2.setBackground(new java.awt.Color(245, 243, 239));

        jLabel1.setFont(new java.awt.Font("DejaVu Sans", 1, 14));
        jLabel1.setText("Médico:");

        jLabel2.setFont(new java.awt.Font("DejaVu Sans", 1, 14));
        jLabel2.setText("CRM:");

        jLabel3.setFont(new java.awt.Font("DejaVu Sans", 1, 14));
        jLabel3.setText("Convenio:");

        nomeMedico.setText(" ");

        crmMedico.setText("   ");

        nomeConvenio.setText("  ");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(nomeMedico, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(crmMedico, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(nomeConvenio, javax.swing.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE)))
                .addGap(93, 93, 93))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(nomeMedico)
                    .addComponent(crmMedico))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(nomeConvenio))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBackground(new java.awt.Color(245, 243, 239));

        jLabel4.setFont(new java.awt.Font("DejaVu Sans", 1, 14));
        jLabel4.setText("Sintomas:");

        nomeConvenio1.setText("  ");

        jLabel5.setFont(new java.awt.Font("DejaVu Sans", 1, 14));
        jLabel5.setText("Diagnóstico:");

        sintomas.setColumns(20);
        sintomas.setRows(5);
        sintomas.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                sintomasKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(sintomas);

        jLabel6.setFont(new java.awt.Font("DejaVu Sans", 1, 14)); // NOI18N
        jLabel6.setText("Exames/Procedimentos:");

        diagnostico.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                diagnosticoKeyTyped(evt);
            }
        });

        adicionarExame.setText("adicionar");
        adicionarExame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adicionarExameActionPerformed(evt);
            }
        });

        removerExame.setText("remover");
        removerExame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removerExameActionPerformed(evt);
            }
        });

        Medicacoes.setFont(new java.awt.Font("DejaVu Sans", 1, 14));
        Medicacoes.setText("Medicações:");

        adicionarMedicacao.setText("adicionar");
        adicionarMedicacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adicionarMedicacaoActionPerformed(evt);
            }
        });

        removerMedicacao.setText("remover");
        removerMedicacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removerMedicacaoActionPerformed(evt);
            }
        });

        medicacoes.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                medicacoesItemStateChanged(evt);
            }
        });

        exames.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                examesItemStateChanged(evt);
            }
        });

        exibirExame.setText("exibir");
        exibirExame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exibirExameActionPerformed(evt);
            }
        });

        exibirMedicacao.setText("exibir");
        exibirMedicacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exibirMedicacaoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addContainerGap(497, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel6)
                                            .addGroup(jPanel3Layout.createSequentialGroup()
                                                .addComponent(adicionarExame)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(removerExame)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(exibirExame, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(exames, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(59, 59, 59)
                                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel3Layout.createSequentialGroup()
                                                .addComponent(adicionarMedicacao)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(removerMedicacao)
                                                .addGap(16, 16, 16)
                                                .addComponent(exibirMedicacao, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(Medicacoes)
                                            .addComponent(medicacoes, 0, 258, Short.MAX_VALUE)))
                                    .addComponent(diagnostico, javax.swing.GroupLayout.PREFERRED_SIZE, 549, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(nomeConvenio1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(14, 14, 14))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addComponent(nomeConvenio1))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(diagnostico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(Medicacoes))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(medicacoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(exames, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(adicionarMedicacao)
                        .addComponent(removerMedicacao)
                        .addComponent(exibirMedicacao))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(adicionarExame)
                        .addComponent(removerExame)
                        .addComponent(exibirExame)))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        salvar.setText("Salvar");
        salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarActionPerformed(evt);
            }
        });

        imprimirProntuario.setText("imprimir");
        imprimirProntuario.setEnabled(false);
        imprimirProntuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                imprimirProntuarioActionPerformed(evt);
            }
        });

        Sair.setText("Sair");
        Sair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SairActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(94, 94, 94)
                        .addComponent(salvar, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(63, 63, 63)
                        .addComponent(imprimirProntuario, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(79, 79, 79)
                        .addComponent(Sair, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(salvar)
                    .addComponent(imprimirProntuario)
                    .addComponent(Sair))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void sintomasKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_sintomasKeyTyped
        changed = true;
    }//GEN-LAST:event_sintomasKeyTyped

    private void diagnosticoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_diagnosticoKeyTyped
        changed = true;
    }//GEN-LAST:event_diagnosticoKeyTyped

    private void adicionarExameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adicionarExameActionPerformed
        ConsultaControler.pegarExame(this);
    }//GEN-LAST:event_adicionarExameActionPerformed

    private void removerExameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removerExameActionPerformed
        if(listaExames != null && listaExames.isEmpty() == false && exameSelecionado != -1){
            this.removerListaExames(listaExames.get(exameSelecionado));
        }
    }//GEN-LAST:event_removerExameActionPerformed

    private void salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarActionPerformed
        if(changed){
            ConsultaControler.atualizaProntuario(consulta.getProtuario(),
                    diagnostico.getText(), sintomas.getText());
        }
    }//GEN-LAST:event_salvarActionPerformed

    private void adicionarMedicacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adicionarMedicacaoActionPerformed
        ConsultaControler.pegarMedicacao(this);        
    }//GEN-LAST:event_adicionarMedicacaoActionPerformed

    private void removerMedicacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removerMedicacaoActionPerformed
        if(listaMedicacoes != null && listaMedicacoes.isEmpty() == false && medicacaoSelecionada != -1){
            this.removerListaMedicacao(listaMedicacoes.get(medicacaoSelecionada));
        }
    }//GEN-LAST:event_removerMedicacaoActionPerformed

    private void SairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SairActionPerformed
        salvarActionPerformed(evt);
        this.dispose();
    }//GEN-LAST:event_SairActionPerformed

    private void medicacoesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_medicacoesItemStateChanged
        medicacaoSelecionada = medicacoes.getSelectedIndex();
    }//GEN-LAST:event_medicacoesItemStateChanged

    private void imprimirProntuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imprimirProntuarioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_imprimirProntuarioActionPerformed

    private void examesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_examesItemStateChanged
        exameSelecionado = exames.getSelectedIndex();
    }//GEN-LAST:event_examesItemStateChanged

private void exibirExameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exibirExameActionPerformed
    if(exameSelecionado != -1){
        javax.swing.JOptionPane.showMessageDialog(null, 
                listaExames.get(exameSelecionado).toString());
    }
}//GEN-LAST:event_exibirExameActionPerformed

private void exibirMedicacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exibirMedicacaoActionPerformed
    if(medicacaoSelecionada != -1){
        javax.swing.JOptionPane.showMessageDialog(jPanel3,
                listaMedicacoes.get(medicacaoSelecionada).toString());
    }
}//GEN-LAST:event_exibirMedicacaoActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Medicacoes;
    private javax.swing.JButton Sair;
    private javax.swing.JButton adicionarExame;
    private javax.swing.JButton adicionarMedicacao;
    private javax.swing.JLabel cpfPaciente;
    private javax.swing.JLabel cpfPaciente1;
    private javax.swing.JLabel cpfPaciente2;
    private javax.swing.JLabel cpfPacientelabel;
    private javax.swing.JLabel crmMedico;
    private javax.swing.JTextField diagnostico;
    private javax.swing.JLabel enderecoPaciente;
    private javax.swing.JComboBox exames;
    private javax.swing.JButton exibirExame;
    private javax.swing.JButton exibirMedicacao;
    private javax.swing.JButton imprimirProntuario;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox medicacoes;
    private javax.swing.JLabel nomeConvenio;
    private javax.swing.JLabel nomeConvenio1;
    private javax.swing.JLabel nomeMedico;
    private javax.swing.JLabel nomePaciente;
    private javax.swing.JButton removerExame;
    private javax.swing.JButton removerMedicacao;
    private javax.swing.JButton salvar;
    private javax.swing.JTextArea sintomas;
    private javax.swing.JLabel telefonePaciente;
    // End of variables declaration//GEN-END:variables

    private void initOtherComponents(Consulta c) {
        consulta = c;
        paciente = PacienteDao.buscar(c.getPacienteCPF());
        nomePaciente.setText(paciente.getNomePaciente());
        cpfPaciente.setText(paciente.getCpfPaciente());
        telefonePaciente.setText(paciente.getTelPaciente());
        enderecoPaciente.setText(paciente.getEndPaciente());

        nomeMedico.setText(new MedicoDao().buscar(c.getMedicoCRM()).getUserName());
        crmMedico.setText(c.getMedicoCRM());

        if(c.getPagamento().getIdConv() == null){
            nomeConvenio.setText("Nenhum");
        }
        else{
            nomeConvenio.setText(c.getPagamento().getIdConv().getNome());
        }

        sintomas.setText(consulta.getProtuario().getSintomas());
        diagnostico.setText(consulta.getProtuario().getDiagnostico());

        
        /*Buscar no banco listaMedicacoes*/
        listaMedicacoes = ConsultaControler.buscarMedicacoes(consulta.getProtuario());

        atualizaMedicacao();

        /*Buscar no banco listaExames*/
        listaExames = ConsultaControler.getAllExames(consulta);
        atualizaExames();
    }

    public void atualizaMedicacao() {
        medicacoes.removeAllItems();
        
        int i;
        for(i=0; i<listaMedicacoes.size(); i++){
                medicacoes.addItem(listaMedicacoes.get(i).toString());
        }
    }

    public void adicionaListaMedicacao(model.Medicacao med) {
       if(med != null){
           ConsultaControler.adicionaMedicacao(consulta.getProtuario(), med);
           listaMedicacoes.add(med);
           atualizaMedicacao();
       }
    }

    public void removerListaMedicacao(model.Medicacao med) {
        if (med != null){
            listaMedicacoes.remove(med);
            ConsultaControler.removeMedicacao(consulta.getProtuario(), med);
            atualizaMedicacao();
        }
 
    }

    private void atualizaExames() {
        exames.removeAllItems();

        int i;
        for(i=0; i<listaExames.size(); i++){
                exames.addItem(listaExames.get(i).toString());
        }
    }

    public void adicionaListaExames(Object exa) {
       if (exa != null){
           ConsultaControler.adicionaExame(consulta, exa);
           listaExames.add(exa);
           atualizaExames();
       }
    }

    public void removerListaExames(Object exa) {
        if (exa != null){
            System.out.println("EAP.removerListaexames");
            listaExames.remove(exa);
            ConsultaControler.removeExame(consulta, exa);
            atualizaExames();
        }
    }
}
